<?php
class My_Controller_Plugin_RequestedModuleLayoutLoader
    extends Zend_Controller_plugin_Abstract
{
	public function init()
	{
		/* Initialize action controller here */
	}

    public function preDispatch(Zend_Controller_Request_Abstract $request)
    {
        $config     = Zend_Controller_Front::getInstance()
                            ->getParam('bootstrap')->getOptions();
        $moduleName = $request->getModuleName();
		if($moduleName == 'admin') {
		/*
			if (isset($config[$moduleName]['resources']['layout']['layout'])) {
				$layoutScript = $config[$moduleName]['resources']['layout']['layout'];
				Zend_Layout::getMvcInstance()->setLayout($layoutScript);
			}

			if (isset($config[$moduleName]['resources']['layout']['layoutPath'])) {
				$layoutPath = $config[$moduleName]['resources']['layout']['layoutPath'];
				$moduleDir = Zend_Controller_Front::getInstance()->getModuleDirectory();
				Zend_Layout::getMvcInstance()->setLayoutPath(
					$moduleDir. DIRECTORY_SEPARATOR .$layoutPath
				);
			}

			Zend_Layout::getMvcInstance()->setLayout('layout');
			Zend_Layout::getMvcInstance()->setLayoutPath($config['resources']['layout']['layoutPath']);
		*/
			Zend_Layout::getMvcInstance()->setLayout('admin');
			Zend_Layout::getMvcInstance()->setLayoutPath($config[$moduleName]['resources']['layout']['layoutPath']);
		} else {
			Zend_Layout::getMvcInstance()->setLayout('layout');
			Zend_Layout::getMvcInstance()->setLayoutPath($config['resources']['layout']['layoutPath']);
		}
    }


}
?>